import { JsonHelper } from "../../../Core/Serialize/JsonHelper";

export class Dictionary<K, V> extends Map<K, V> {

    public Add(key: K, value: V) {
        this.set(key, value);
    }

    public Remove(key: K): V;
    public Remove(key: K, value: V): V;
    public Remove(key: K, value?: V): V {
        value = this.TryGetValue(key);
        if (value) {
            this.delete(key);
            return value;
        }
        return null;
    }

    public RemoveValue(key: K) {
        let value = this.TryGetValue(key);
        if (value) {
            this.Remove(key);
        }
        return value;
    }

    public Clear() {
        this.clear();
    }

    public TryGetValue(key: K): V {
        if (this.ContainsKey(key)) {
            return this.get(key);
        }
        return null;
    }

    public ContainsKey(key: K) {
        return this.has(key);
    }

    public ContainsValue(value: V) {
        return false;
    }

    public ToString() {
        console.log(JsonHelper.ToJson(this));
        console.log("Dictionary.ToString")
    }

    public get Count(): number {
        return this.size;
    }

    public *Values(): Generator<V> {
        for (const value of this.values()) {
            yield value;
        }
    }

}